package com.xncoding.freemarker.utile;

import com.google.common.base.Charsets;
import com.google.common.io.Files;

import java.io.File;
import java.io.IOException;

public class GuavaIOExamplePractical {

    public static void main(String[] args) {
        File inputFile = new File("/Users/ligang/Desktop/desk/111.txt");
        File outputFile = new File("/Users/ligang/Desktop/desk/output.txt");

        try {
            // 使用Files.asCharSource读取文件内容
            String content = Files.asCharSource(inputFile, Charsets.UTF_8).read();

            // 使用Java 8的流操作进行转换（这里转换为大写）
            String upperCaseContent = content.chars()
                    .mapToObj(c -> (char) c)
                    .map(String::valueOf)
                    .map(String::toUpperCase)
                    .reduce((a, b) -> a + b)
                    .orElse("");

            // 使用Files.asCharSink写入文件内容
            Files.asCharSink(outputFile, Charsets.UTF_8).write(upperCaseContent);

            System.out.println("File processed successfully with Guava and Java 8 streams.");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}